using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ghasam.Business.Services;
using Mani.Common;

public partial class OverTimeWork : System.Web.UI.Page
{
    #region"Private Property"

    private IOverTimeWorkPaymentService overTimeWorkPaymentService;
    private IEmployeeService employeeService;
    #endregion
    #region"Public Property"

    public IOverTimeWorkPaymentService OverTimeWorkPaymentService
    {
        set { overTimeWorkPaymentService = value; }
        get { return overTimeWorkPaymentService; }
    }

    public IEmployeeService EmployeeService
    {
        set { employeeService = value; }
        get { return employeeService; }
    }
    #endregion
    #region"Private Method"

    private void checkMonth(int month)
    {
        txtStartDt.Text = string.Format("{0}/{1}/01", MyPersianDate.Persian.GetYear(DateTime.Today.Date), ddlMonth.SelectedValue);
        if (month > 6)
            txtEndDt.Text = string.Format("{0}/{1}/30", MyPersianDate.Persian.GetYear(DateTime.Today.Date), ddlMonth.SelectedValue);
        else
            txtEndDt.Text = string.Format("{0}/{1}/31", MyPersianDate.Persian.GetYear(DateTime.Today.Date), ddlMonth.SelectedValue);
    }

    private void checkEmployee(int empId)
    {
        Ghasam.Business.Domain.Entity.Employee emp = new Ghasam.Business.Domain.Entity.Employee();
        emp = EmployeeService.GetById(empId);
        lblName.Visible = true;
        lblName.Text = string.Format("{1} {0}", emp.FirstName, emp.LastName);
    }

    private void Save()
    {
        OverTimeWorkPaymentService.OverTimeWorkSaveOrUpdate(
            Convert.ToInt32(txtEmpId.Text), (float)Convert.ToDouble(txtHours.Text), MyPersianDate.PersianToDateTime(txtStartDt.Text), MyPersianDate.PersianToDateTime(txtEndDt.Text), chkHoliday.Checked, chkNightly.Checked);
    }

    #endregion

    #region"Events"

    protected void Page_Load(object sender, EventArgs e)
    {
        checkMonth(Convert.ToInt32(ddlMonth.SelectedValue));
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            Save();
            lblSaveMsg.Visible = true;
        }
        catch (Exception ex)
        { throw ex; }
    }
    protected void ddlMonth_SelectedIndexChanged(object sender, EventArgs e)
    {
        checkMonth(Convert.ToInt32(ddlMonth.SelectedValue));
    }
    protected void btnCheckEmp_Click(object sender, EventArgs e)
    {
        if (txtEmpId.Text.Length > 0)
            checkEmployee(Convert.ToInt32(txtEmpId.Text));
    }
    #endregion


    protected void chkIsFormal_CheckedChanged(object sender, EventArgs e)
    {

    }
}
